<template>
  <el-dialog
    v-model="dialogVisible"
    width="350px"
    style="
      background: #222222;
      border-radius: 9px;
      border: 1px solid rgba(255, 255, 255, 0.5);
      padding: 0;
    "
    :modal="false"
    :before-close="close"
    align-center
    @close="close"
  >
    <template #header>
      <div class="title">设置麦位名称</div>
    </template>
    <template #default>
      <div class="dialog-content">
        <el-input
          v-model="inputValue"
          placeholder="请输入麦位名称"
          style="width: 220px"
          clearable
        />
        <div style="color: #fff; font-size: 12px; margin-top: 8px">当前麦位：{{ oldName }}</div>
      </div>
      <div class="btns">
        <span class="btn" @click="close">取消</span>
        <span class="btn" style="color: #ff4e6c" @click="handleSubmit">确认</span>
      </div>
    </template>
  </el-dialog>
</template>
<script lang="ts" setup>
import { ref } from "vue";

const dialogVisible = ref(false);
const inputValue = ref(""); // 设置新的麦位名称
const oldName = ref(""); // 旧的麦位名称
const emit = defineEmits(["submit"]);
// 显示
const show = (name: string) => {
  oldName.value = name;
  dialogVisible.value = true;
};

// 关闭前的回调
const close = () => {
  dialogVisible.value = false;
  inputValue.value = "";
  oldName.value = "";
};
const handleSubmit = () => {
  emit("submit", inputValue.value);
};

defineExpose({ show, close });
</script>
<style lang="scss" scoped>
.title {
  padding: 15px 32px 0px;
  font-size: 16px;
}
.dialog-content {
  border-top: 1px solid rgba(216, 216, 216, 0.5);
  border-bottom: 1px solid rgba(216, 216, 216, 0.5);
  padding: 20px 20px 30px;
}
.btns {
  padding: 14px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 7px;
  .btn {
    padding: 7px 16px;
    font-size: 12px;
    color: #8a8a8a;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    cursor: default;
  }
}
</style>
